﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TagLib;

namespace Kinect_Interface_Prototype_1.Kinect_MediaPlayer
{
    public class Song : Media
    {
        public string Path { get; set; }
        public string Extention { get; set; }

        public string Title { get; set; }
        public string Artist { get; set; }
        public string Album { get; set; }
        public string Year { get; set; }
        public string Comment { get; set; }
        public List<string> Genre { get; set; }
        public int Track { get; set; }
        public double LengthSeconds { get; set; } //in seconds
        public double LengthMilliseconds { get; set; } // in milliseconds
        public double Minutes { get; set; }
        public double Seconds { get; set; }

        public Song(string fileName)
        {
            // Using TagLib Reference
            TagLib.File fileProperties = TagLib.File.Create(fileName);

            //if (fileProperties.Tag.Pictures.Count() > 0)
            //{
            //    fileProperties.Tag.Pictures = new IPicture[0];
            //    fileProperties.Save();
            //}

            Tag tag = fileProperties.Tag;

            Path = fileName;
            Extention = fileName.Substring(fileName.LastIndexOf(".") + 1);
            Title = tag.Title;
            Artist = tag.FirstAlbumArtist;
            Album = tag.Album;
            Year = tag.Year.ToString();
            Comment = tag.Comment;
            Genre = tag.Genres.ToList();
            Track = (int)tag.Track;
            LengthMilliseconds = fileProperties.Properties.Duration.TotalMilliseconds;
            LengthSeconds = LengthMilliseconds/1000;
            Minutes = fileProperties.Properties.Duration.Minutes;
            Seconds = fileProperties.Properties.Duration.Seconds;
        }
    }
}
